#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 100000;

struct node {
    string xm, xh;
    int cj;
}a[N];

bool cmp(node x, node y) {
    return x.cj < y.cj;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i].xm >> a[i].xh >> a[i].cj;
    }
    sort(a, a + n, cmp);
    cout << a[n - 1].xm << " " << a[n - 1].xh << endl << a[0].xm << " " << a[0].xh << endl;
}